
(function () {
  var nums = []
  var cate = []
  $.ajax({
    method: 'GET',
    url: '/index/baseInfo',

    success: function (res) {
      const { data, errno } = res
      if (errno !== 0) return layer.msg('获取失败')
      // const { article_num, admin_num, advimg_num, advpos_num, total } = data
      $('.heihei').html(data.article_num)
      $('.meme').html(data.admin_num)
      $('.jjxx').html(data.user.total)
      $('.zzww').html(data.advpos_num)
      $('.xxjj').html(data.advimg_num)
      // console.log(data);
      // // console.log("nan", nan)
      // const feilei = data.all_cate.catename
      // console.log("feilei", feilei)
      // const shuliang = data.all_num
      // console.log("shuliang", shuliang)
      // console.log("nv", nv)
      // const { all_cate } = data
      // console.log(all_cate);
      const { all_cate } = data
      if (all_cate) {
        for (let i = 0; i < all_cate.length; i++) {
          nums.push(all_cate[i].num)
          cate.push(all_cate[i].catename)
        }
      }


      // console.log(nums);
      // console.log(nums);
      // console.log(res);


      // console.log(all_cate)

      const zzw = data.hot_article.map(function (item) {
        return `
      <div class="fzz">
      <span>${item.title}</span>
  
    </div>
      `
      })
      $('.lj').html(zzw.join(''))

      const jx = data.new_user.map(function (item) {
        return `
      <div class="jx">
      <span>${item.username}</span>
      <i>${item.sex = 1 ? '女' : '男'}</i>
      </div>
        `
      })
      $('.lq').html(jx.join(''));

      (function () {
        var myChart = echarts.init(document.querySelector(".zf"));
        var option = {
          tooltip: {
            trigger: 'item'
          },
          legend: {
            top: '5%',
            left: 'center'
          },
          series: [
            {
              name: '用户来源',
              type: 'pie',
              radius: ['40%', '70%'],
              avoidLabelOverlap: false,
              itemStyle: {
                borderRadius: 10,
                borderColor: '#fff',
                borderWidth: 2
              },
              label: {
                show: false,
                position: 'center'
              },
              emphasis: {
                label: {
                  show: true,
                  fontSize: 40,
                  fontWeight: 'bold'
                }
              },
              labelLine: {
                show: false
              },
              data: [
                { value: data.user.user_woman, name: '女性' },
                { value: data.user.user_man, name: '男性' }

              ]
            }
          ]
        };


        myChart.setOption(option);
      })();

      (function () {
        var myChart = echarts.init(document.querySelector(".last1"));
        var option = {
          xAxis: {
            type: 'category',
            data: cate
          },
          yAxis: {
            type: 'value',
            min: 0, //y轴的最小值
            max: 140, //y轴最大值
            interval: 20, //值之间的间隔

          },
          series: [
            {
              data: nums,
              type: 'bar',
              showBackground: true,
              backgroundStyle: {
                color: 'rgba(180, 180, 180, 0.2)'
              }
            }
          ]
        }

        myChart.setOption(option)
      })();
    }
  })
})();

